/**
 * 
 */
package com.audi.handler;

import android.os.Message;

import com.audi.message.AudiMessage;
import com.google.gson.Gson;

/**
 * @author PhongNT11
 * 
 */
public class MessageHandler {
	private Gson gson;
	private HandlerFactory handlerFactory;

	public MessageHandler() {
		gson = new Gson();
		handlerFactory = HandlerFactory.getInstance();
	}

	/**
	 * processMessage
	 * 
	 * @param data
	 *            msg
	 * @return Message
	 * @see receive message, process message and return UI
	 */
	public Message processMessage(String msg) {
		AudiMessage aMsg = gson.fromJson(msg, AudiMessage.class);
		int actionId = aMsg.getActionID();
		String data = aMsg.getData();
		Handler handler = handlerFactory.getHandler(actionId);
		Message message = handler.process(actionId, data);
		return message;
	}
}
